package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.UsersFriend;
import com.example.demo.entity.dto.MyFriendsAddInfoDTO;
import com.example.demo.mapper.UsersFriendMapper;
import com.example.demo.service.IUsersFriendService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 好友关系 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2024-03-13
 */
@Service
public class UsersFriendServiceImpl extends ServiceImpl<UsersFriendMapper, UsersFriend> implements IUsersFriendService {

    @Override
    public boolean addFriend(UsersFriend usersFriend) {
        //查询是否已经是好友 status为1（同意）或3（拉黑）就不允许二次添加
        //如果不存在以上情况就添加，能换行写就换行写，ok?
        //条件构造器
        QueryWrapper<UsersFriend> queryWrapper = new QueryWrapper<UsersFriend>()
            .eq("user_id", usersFriend.getUserId())
            .eq("friend_id", usersFriend.getFriendId())
            .in("status",0,1,3);
        //查询条数 当跳数0
        if(this.count(queryWrapper) == 0){
            this.save(usersFriend);
            return true;
        }
        return false;
    }

    @Override
    public List<MyFriendsAddInfoDTO> getMyFriendsAddInfo(Integer id) {
        return getBaseMapper().getMyFriendsAddInfoMapper(id,0);
    }

    @Override
    public List<MyFriendsAddInfoDTO> getMyFriends(Integer id) {
        return getBaseMapper().getMyFriendsAddInfoMapper(id,1);
    }
}
